/*
 * Copyright 2009 IT Mill Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.sasha.roulette;

import org.sasha.roulette.data.DBHelper;
import org.sasha.roulette.event.SessionChangedEvent;
import org.sasha.roulette.guice.RouletteModule;

import com.google.common.eventbus.EventBus;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.vaadin.Application;
import com.vaadin.ui.Window;

/**
 * The Application's "main" class
 */
@SuppressWarnings("serial")
public class RoultetteTrackerApplication extends Application {

    private Injector injector;
    
    private Window window = new Window("Трекер");
    
    @Override
    public void init() {
        setTheme("roulette");
        SessionContext.initialize(this);
        injector = Guice.createInjector(new RouletteModule(this));
        window.setContent(injector.getInstance(RouletteView.class).getViewComponent());
        setMainWindow(window);
        int currentSessionId = injector.getInstance(DBHelper.class).getLatestSessionID();
        SessionContext.get().setSessionId(currentSessionId);
        injector.getInstance(EventBus.class).post(new SessionChangedEvent(currentSessionId));
    }

}
